{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Basic Clipperplus Tests"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import clipperpluspy\n",
    "import unittest"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "class TestClipperplus(unittest.TestCase):\n",
    "    \n",
    "    test_data = [\n",
    "        {\"name\": \"Adjacency Matrix 1\",\n",
    "         \"adj\": np.array([[0, 0, 1, 1, 1, 1, 1, 0, 1, 0],\n",
    "                          [0, 0, 1, 1, 1, 0, 1, 1, 1, 1],\n",
    "                          [1, 1, 0, 1, 0, 1, 1, 1, 0, 1],\n",
    "                          [1, 1, 1, 0, 1, 1, 1, 1, 1, 1],\n",
    "                          [1, 1, 0, 1, 0, 0, 1, 1, 1, 1],\n",
    "                          [1, 0, 1, 1, 0, 0, 1, 1, 1, 1],\n",
    "                          [1, 1, 1, 1, 1, 1, 0, 1, 1, 0],\n",
    "                          [0, 1, 1, 1, 1, 1, 1, 0, 1, 1],\n",
    "                          [1, 1, 0, 1, 1, 1, 1, 1, 0, 1],\n",
    "                          [0, 1, 1, 1, 1, 1, 0, 1, 1, 0]]),\n",
    "         \"expected_clique_size\": 6,\n",
    "         \"expected_clique\": [1, 3, 4, 6, 7, 8],\n",
    "         \"expected_certificate\": 0},\n",
    "        {\"name\": \"Adjacency Matrix 2\",\n",
    "         \"adj\": np.array([[0, 0, 1, 1, 1, 1, 1, 1, 1, 1],\n",
    "                          [0, 0, 1, 1, 1, 1, 1, 1, 1, 1],\n",
    "                          [1, 1, 0, 1, 1, 1, 1, 1, 1, 1],\n",
    "                          [1, 1, 1, 0, 1, 1, 1, 0, 1, 1],\n",
    "                          [1, 1, 1, 1, 0, 1, 0, 1, 1, 0],\n",
    "                          [1, 1, 1, 1, 1, 0, 1, 1, 1, 1],\n",
    "                          [1, 1, 1, 1, 0, 1, 0, 1, 1, 1],\n",
    "                          [1, 1, 1, 0, 1, 1, 1, 0, 1, 1],\n",
    "                          [1, 1, 1, 1, 1, 1, 1, 1, 0, 1],\n",
    "                          [1, 1, 1, 1, 0, 1, 1, 1, 1, 0]]),\n",
    "         \"expected_clique_size\": 7,\n",
    "         \"expected_clique\": [6, 0, 2, 3, 5, 8, 9],\n",
    "         \"expected_certificate\": 3},\n",
    "        {\"name\": \"Adjacency Matrix 3\",\n",
    "         \"adj\": np.array([[0, 0, 1, 0, 0, 1, 1, 1, 0, 0, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1],\n",
    "                          [0, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1, 1],\n",
    "                          [1, 1, 0, 1, 0, 1, 0, 1, 1, 1, 0, 1, 1, 0, 0, 1, 1, 1, 1, 0],\n",
    "                          [0, 1, 1, 0, 0, 1, 1, 1, 1, 0, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1],\n",
    "                          [0, 1, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],\n",
    "                          [1, 1, 1, 1, 0, 0, 1, 0, 1, 0, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1],\n",
    "                          [1, 1, 0, 1, 1, 1, 0, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1],\n",
    "                          [1, 1, 1, 1, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0],\n",
    "                          [0, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 0],\n",
    "                          [0, 1, 1, 0, 1, 0, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1],\n",
    "                          [1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1],\n",
    "                          [1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1, 0, 1, 1, 1],\n",
    "                          [0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 1, 1],\n",
    "                          [1, 1, 0, 1, 1, 0, 1, 1, 1, 0, 1, 0, 0, 0, 1, 1, 1, 1, 1, 1],\n",
    "                          [1, 1, 0, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1],\n",
    "                          [1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0],\n",
    "                          [1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 0, 1, 1, 1, 0, 1, 1, 0],\n",
    "                          [1, 0, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1],\n",
    "                          [0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1],\n",
    "                          [1, 1, 0, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 0]]),\n",
    "         \"expected_clique_size\": 8,\n",
    "         \"expected_clique\": [4, 10, 13, 14, 15, 16, 17, 18],\n",
    "         \"expected_certificate\": 0}\n",
    "    ]\n",
    "    def test_clique(self):\n",
    "        for i in range(len(self.test_data)):\n",
    "            with self.subTest(\"Finding cliques on predetermined adjacency matrices\", i=i):\n",
    "                adj = self.test_data[i][\"adj\"]\n",
    "                clique_size, clique, certificate = clipperpluspy.clipperplus_clique(adj)\n",
    "                print(f\"\\nTest {i}: {self.test_data[i]['name']}\\n\")\n",
    "                print(f\"{self.test_data[i]['adj']}\\n\", flush=True)\n",
    "                self.assertEqual(clique_size, self.test_data[i][\"expected_clique_size\"])\n",
    "                self.assertEqual(clique, self.test_data[i][\"expected_clique\"])\n",
    "                self.assertEqual(certificate, self.test_data[i][\"expected_certificate\"])\n",
    "                print(flush=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "unittest.main(argv=[''], verbosity=2, exit=False)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
